1. Field of the Invention
The present invention relates to a program compilation execution system which comprises a compiler for compiling a source program and generating an object program, a linker for receiving the object program and outputting an execution format file and a program execution portion for executing the execution format file, and especially to a program compilation execution system in which when a program is compiled and executed by dividing the program into plural tasks, an in-task shared data allocation system is used for efficiently allocating a memory used by each task.
2. Description of the Related Art
In a conventional in-task shared data allocation system, for example, as described in Japanese Patent Application Laid-open No. Hei 7-78092, when a batch of processing is divided in tasks for execution, a data region to be used by the tasks is allocated on a main memory of a computer.
FIG. 11 is a block diagram showing a constitution of the above related art. Referring to FIG. 11, numeral 1001 denotes a task switch controller for switching an active task to another task, 1002 denotes a stack data movement controller for relocating each stack in a stack region, and 1003 denotes a stack information memory for storing stack address information. Also, numeral 1004 is a stack pointer for pointing a position in the stack region. Data is outputted or inputted at the position pointed by the stack pointer. Numeral 1005 denotes a stack region in which stack data for the respective tasks are stored in a batch, and is constituted of an empty region 1005a in which data is not yet stored and a stack data group 1005b in which data is already stored. A boundary address 1006 between the empty region 1005a and the stack data group 1005b varies in accordance with the amount of the stored stack data. The boundary address 1006 is constantly pointed by the stack pointer 1004.
The stack region 1005 will be described in more detail with reference to FIG. 12. FIG. 12 shows a condition in which the active task is switched from task 1 to task 3. FIG. 12A shows the stack region 1005 before the task is switched, while FIG. 12B shows the stack region 1005 after the task is switched.
In the stack region 1005, the stack data group 1005b is divided into stack data 1011 to 1014 for respective tasks 1 to 4. These stack data are not provided with individual empty regions, but instead the empty region 1005a is provided in common.
As shown in FIG. 12A, before the task is switched, the task 1 is active. Therefore, the stack data 1011 of the task 1 is adjacent to the empty region 1005a. The boundary address 1006 between the common empty region 1005a and the stack data 1011 is pointed by the stack pointer 1004, from or to which data can be outputted or inputted. Specifically, when fetching data, data is fetched into the common empty region 1005a, which thus becomes a part of the stack data 1011. On the other hand, data is fetched from the stack data 1011, thereby enlarging the common empty region 1005a.
As shown in FIG. 12B, after the task is switched, the task 3 becomes a starting task. Therefore, the stack data 1013 of the task 3 is adjacent to the empty region 1005a. From or to the stack data 1013 data can be outputted or inputted. In this manner, before and after the task is switched, the stack data is moved without moving the stack pointer 1004.
Operation of the stack data switch device constituted as mentioned above will be described. First, when a request for switching the task arises, the task switch controller 1001 receives the task switching request. Subsequently, the task switch controller 1001 sends information of start and stop tasks to the stack data movement controller 1002. Subsequently, the stack data movement controller 1002 receives information of each task stack address and stack data size from the stack information memory 1003. Then, the stack data movement controller 1002 moves stack data within the stack data group 1005b of the stack region 1005, so that the stack data of the starting task is brought to the stack address pointed by the stack pointer 1004. Subsequently, the stack data movement controller 1002 stores the information of each stack address and stack data size in the stack information memory 1003 in accordance with the moved stack data.
Operation in the stack region 1005 will be described with reference to FIG. 12. First, as shown in FIG. 12A, before the task is switched, the stack data 1014 of the task 4 is in the deepest position, the stack data 1013 of the task 3 is next to the stack data 1014, and the stack data 1012 of the task 2 is next to the stack data 1013. Then, in the shallowest position, the stack data 1011 of the task 1 being active is present in the stack address pointed by the stack pointer 1004.
When the active task is switched from the task 1 to the task 3 in the above stack condition, the stack data of each task is moved as shown in the stack region 1005 of FIG. 12B.
First, the stack data 1013 of the task 3 is moved to the stack address pointed by the stack pointer 1004. Subsequently, the stack data 1011 of the task 1 and the stack data 1012 of the task 2 which have been in the position shallower than that of the stack data 1013 are moved to the position deeper than that of the stack data 1013. The stack data 1014 of the task 4 is not moved and stays as it is.
As aforementioned, by moving the stack data of each task without switching the stack pointer 1004, one empty region can be shared by respective tasks. Therefore, only the stack region necessary for the entire device may be reserved, thereby saving wastes resulting when a stack region is reserved for each task.
However, in the aforementioned conventional stack data switch device, there is a problem that an initial stack size which is allocated when starting each task is necessarily fixed on the stack. Specifically, if the initial stack region of each task has therein a region which is not actually used by the task, the unused region is secured on the stack. Thus, memory is wasted.
This problem arises especially in the case where in a shared memory multiprocessor system, a program is executed by dividing the program into plural tasks, each task is executed on a separate CPU and variables declared globally in the program have to be secured in a separate region for each task. This is because all the variables declared globally are reserved in the stack region of each task.
Specifically, even the global variable which is unnecessary for some task is reserved in the initial stack region of the task. In other words, when the number of tasks is N and the size of the global variable is S, the stack region having a size of N*S is secured in the entire system. If S has a relatively large value, the size of N*S in some case becomes larger than the stack size of the system. Therefore, the program cannot be executed, and another problem arises.
Also, in the conventional stack data switch device, the data instead of the stack pointer is moved. Therefore, another problem is that overhead for moving the data is enlarged in proportion to the size of the data region.
An object of the present invention is to provide a program compilation execution system using an in-task shared data allocation system in which by allocating only the data to be used in a task to a main memory region of the task, the operation efficiency of the main memory region can be enhanced.
Another object of the invention is to provide a program compilation execution system using an in-task shared data allocation system which can prevent overhead at the time of switching a task from increasing in proportion to the amount of data generated when switching stack data as in a conventional art.